// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include <cstring>
#include <vector>

#include <gtest/gtest.h>

#include "DataStructure/Common/Status.h"

#include "DBManager/IService/Result/ElementalForce/IELAS1ForceService.h"
#include "DBManager/UnitTest/HDF5/TestDB.h"

using namespace SG::DataStructure::Post;
using namespace SG::DBManager;

TEST (O_ForceServiceTest, ELAS1ForceServiceTest)
{
    DB::ServiceFactory->ClearDatabase ();
    // 获取仓库服务
    auto service = DB::ServiceFactory->get<IELAS1ForceService> ();
    // 创建存储的数据，添加数据
    std::vector<ELAS1ForceData> saveData;

    ELAS1ForceData data;

    for (SG::DataStructure::Common::Id i = 0; i < 10; i++)
    {
        data.m_eId      = i;
        data.m_domainId = 1;
        saveData.push_back (data);
    }
    ASSERT_EQ (service->Add ({ SG::DataStructure::FEM::SOLType::SOL_SESTATIC, 1 }, saveData),
               SG::DataStructure::Common::Status::STATUS_Success);
    saveData.clear ();

    // 创建存储的数据，添加数据
    for (SG::DataStructure::Common::Id i = 0; i < 10; i++)
    {
        data.m_eId      = i;
        data.m_domainId = 2;
        saveData.push_back (data);
    }
    ASSERT_EQ (service->Add ({ SG::DataStructure::FEM::SOLType::SOL_SESTATIC, 2 }, saveData),
               SG::DataStructure::Common::Status::STATUS_Success);

    // 创建判断的数据
    for (SG::DataStructure::Common::Id i = 0; i < 10; i++)
    {
        data.m_eId      = i;
        data.m_domainId = 2;
        saveData.push_back (data);
    }

    // 通过DomainId获取数据，测试接口正确性
    std::vector<ELAS1ForceData> result;
    ASSERT_EQ (service->Find ({ SG::DataStructure::FEM::SOLType::SOL_SESTATIC, 2 }, result),
               SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_EQ (result.size (), 10);
    for (SG::DataStructure::Common::Id i = 0; i < 10; i++)
    {
        ASSERT_EQ (saveData[i], result[i]);
    }

    // 通过DomainId与实体ID获取数据，测试接口正确性
    ASSERT_EQ (service->Find ({ SG::DataStructure::FEM::SOLType::SOL_SESTATIC, 2 }, { 1 }, _OUT result),
               SG::DataStructure::Common::Status::STATUS_Success);
    ASSERT_EQ (result[0].m_eId, 1);
    ASSERT_EQ (result[0].m_domainId, 2);
}